import shapefile


w = shapefile.Writer("shapefiles/shapefiles")

# 1. 添加点
w.field('name', 'C')
w.point(122, 37)
w.record('point1')

# 2. 添加多个点
w.multipoint([[122, 37], [124, 32]])
w.record('multipoint1')

# 3.添加多条线
w.line([
    [[1, 5], [5, 5], [5, 1], [3, 3], [1, 1]],  # line 1
    [[3, 2], [2, 6]]  # line 2
])
w.record('linestring1')

# 4.添加多边形
w = shapefile.Writer('shapefiles/test/polygon')
w.field('name', 'C')
w.poly([
    [[113, 24], [112, 32], [117, 36], [122, 37], [118, 20]],  # poly 1
    [[116, 29], [116, 26], [119, 29], [119, 32]],  # hole 1
    [[15, 2], [17, 6], [22, 7]]  # poly 2
])
w.record('polygon1')

w.close()